package lab02.Text24;

import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

/**
 * Created by Administrator on 2017/11/2.
 */
public class Text {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入第一个日期：");         //格式为：20170319
        String result= scanner.nextLine();
        String year =result.substring(0,4);
        String month =result.substring(4,6);
        String day =result.substring(6);
        Calendar calendar = Calendar.getInstance();
        calendar.set(Integer.parseInt(year),Integer.parseInt(month),Integer.parseInt(day));
        Date date1 = calendar.getTime();
        System.out.println("请输入第二个日期：");
        result = scanner.nextLine();
        year =result.substring(0,4);
        month =result.substring(4,6);
        day =result.substring(6);
        calendar.set(Integer.parseInt(year),Integer.parseInt(month),Integer.parseInt(day));
        Date date2 = calendar.getTime();
        long SubDay = (date1.getTime()-date2.getTime())/(24*60*60*1000);
        if (SubDay < 0)  SubDay = (date2.getTime()-date1.getTime())/(24*60*60*1000);
        System.out.println("两个日期之间相差"+SubDay+"天");
    }
}
